package com.neusoft.neuiotms.dcvm.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcvm.dto.AlarmDTO;
import com.neusoft.neuiotms.dcvm.model.Alarm;
import com.neusoft.neuiotms.dcvm.repository.AlarmRepository;

@Component
public class AlarmConverter extends AbstractConverter<Alarm, AlarmDTO> {

    @Autowired
    private AlarmRepository alarmepository;

    @Override
    public Alarm toModel(final AlarmDTO dto) {
        Alarm model;
        if (dto.isNew()) {
            model = new Alarm();
        } else {
            model = this.alarmepository.getOne(dto.getId());
        }
        model.setAlarmId(dto.getAlarmId());
        model.setAlarmLevel(dto.getAlarmLevel());
        model.setAlarmContent(dto.getAlarmContent());
        model.setAlarmTime(dto.getAlarmTime());
        model.setAssetCode(dto.getAssetCode());
        model.setAssetName(dto.getAssetName());
        model.setCabinetCode(dto.getCabinetCode());
        model.setCabinetName(dto.getCabinetName());
        model.setLocationCode(dto.getLocationCode());
        model.setLocationName(dto.getLocationName());
        model.setSourceType(dto.getSourceType());
        return model;
    }

    @Override
    public AlarmDTO toDTO(final Alarm model, final boolean forListView) {
        final AlarmDTO dto = new AlarmDTO();
        dto.setId(model.getId());
        dto.setAlarmId(model.getAlarmId());
        dto.setAlarmLevel(model.getAlarmLevel());
        dto.setAlarmContent(model.getAlarmContent());
        dto.setAlarmTime(model.getAlarmTime());
        dto.setAssetCode(model.getAssetCode());
        dto.setAssetName(model.getAssetName());
        dto.setCabinetCode(model.getCabinetCode());
        dto.setCabinetName(model.getCabinetName());
        dto.setLocationCode(model.getLocationCode());
        dto.setLocationName(model.getLocationName());
        dto.setSourceType(model.getSourceType());
        return dto;
    }
}
